/*已知在一维数组A[m+n]中依次存放着两个顺序表(a0,a1,···,a(m-1))和(b0,b1,···,b(n-1))。试编写一个函数，将数组中两个顺序表的位置互换，即将(b0,b1,···,b(n-1))放到(a0,a1,···,a(m-1))前面*/

#include <stdio.h>

void func1(int m, int n, int *arr)
{
     int len = m + n;
     int A[m];
     for (int i = 0; i < m; i++)
          A[i] = arr[i];
     for (int i = 0; i < n; i++)
          arr[i] = arr[i + m];
     for (int i = n; i < m + n; i++)
          arr[i] = A[i - n];
}

void reverse(int *arr, int len)
{
     int i = 0, j = len - 1;
     int tmp;
     while (i < j)
     {
          tmp = arr[i];
          arr[i] = arr[j];
          arr[j] = tmp;
          ++i;--j;
     }
}

void func2(int m, int n, int *arr)
{
     reverse(arr, m + n);
     reverse(arr + 10, m);
     reverse(arr, n);
}
int main(void)
{
     int m = 5, n = 10;
     int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

     //func1(m, n, arr);

     func2(m,n,arr);

     for (int i = 0; i < m + n; i++)
          printf("%d  ", arr[i]);
     printf("\n");

     return 0;
}
